package com.yulintu.mq;

import com.yulintu.common.ProcessManager;
import com.yulintu.utils.FileParser;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * @author caomin
 * @date 2017/6/5
 * @说明 消费者
 */

@Component
public class FileReceiver {

    @Autowired
    FileParser fileParser;

    @RabbitListener(queues = {"fileQueue"})
    @RabbitHandler
    public  void processFileMessage(File file) throws Exception {
        System.out.println("接收文件:"+file.getName()+"并准备解析");
        ProcessManager.getProcessManager().getThreadPool().execute(fileParser.setFile(file));
    }
}
